import { _decorator, Button, Component, Node, resources, SpriteFrame, tween, Vec3 } from 'cc';
const { ccclass, property } = _decorator;

@ccclass('levelEnd')
export class levelEnd extends Component {


    private timeCur = 10

    private starImg:SpriteFrame = null


    onLoad() {
        this.node.getChildByName('levelpage').on(Button.EventType.CLICK, this.callbackLevelpage, this);
        this.node.getChildByName('again').on(Button.EventType.CLICK, this.callbackAgain, this);
        this.node.getChildByName('next').on(Button.EventType.CLICK, this.callbackNext, this);
    }

    start() {
        this.starTwen()
    }

    callbackLevelpage() {
        console.log("关卡界面")

    }
    callbackAgain() {
        console.log("复活")

    }
    callbackNext() {

        console.log('下一关')
    }

    //三颗星的缓动
    starTwen() {

        if (this.timeCur == 0) {
            return
        }

        //第一颗星
        if (this.timeCur > 0) {

            resources.load(`img/bf11/spriteFrame`, SpriteFrame, (err, spriteFrame) => {
                if (err) {
                    console.error("资源加载游戏界面bg资源失败: ", err);
                    return;
                }
                console.log("动态加载了游戏界面背景");
                if (sprite) {




                    this.starImg = spriteFrame;
                } else {
                    console.error("heart 没有 Sprite 组件");
                }
            });
            tween(this.node.getChildByName('star1'))
                .to(0.2, { scale: new Vec3(1.2, 1.2, 1) }, { easing: 'sineInOut' }) // 放大到1.2倍
                .to(0.2, { scale: new Vec3(0.8, 0.8, 1) }, { easing: 'sineInOut' }) // 缩小到1倍
                // .repeatForever() // 设置动画循环播放 3 次
                .start(); // 开始动画
            if (this.timeCur >= 240) {
                tween(this.node.getChildByName('star2'))
                    .to(0.2, { scale: new Vec3(1.2, 1.2, 1) }, { easing: 'sineInOut' }) // 放大到1.2倍
                    .to(0.2, { scale: new Vec3(0.8, 0.8, 1) }, { easing: 'sineInOut' }) // 缩小到1倍
                    // .repeatForever() // 设置动画循环播放 3 次
                    .start(); // 开始动画
            }
            if (this.timeCur > 270) {
                tween(this.node.getChildByName('star3'))
                    .to(0.2, { scale: new Vec3(1.2, 1.2, 1) }, { easing: 'sineInOut' }) // 放大到1.2倍
                    .to(0.2, { scale: new Vec3(0.8, 0.8, 1) }, { easing: 'sineInOut' }) // 缩小到1倍
                    // .repeatForever() // 设置动画循环播放 3 次
                    .start(); // 开始动画
            }
        }

    }

}


